package com.crk.yiyuanguahao.controller;

import com.crk.yiyuanguahao.entity.DoctorAppointment;
import com.crk.yiyuanguahao.service.DoctorAppointmentService;
import com.crk.yiyuanguahao.service.DoctorService;
import com.crk.yiyuanguahao.util.LayUiTableJson;
import com.crk.yiyuanguahao.util.Page;
import com.crk.yiyuanguahao.util.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author
 * @description:
 * @date 2020/3/26
 */
@RestController
@RequestMapping("doctorAppointment")
public class DoctorAppointmentController {
    @Autowired
    DoctorAppointmentService doctorAppointmentService;

    @RequestMapping("manage")
    public ModelAndView manage(){
        ModelAndView modelAndView = new ModelAndView("/workspace/doctorAppointment/doctorAppointmentList.html");
        return modelAndView;
    }

    @GetMapping("detail")
    public ModelAndView detail(){
        ModelAndView modelAndView = new ModelAndView("/workspace/doctorAppointment/doctorAppointmentAdd.html");
        return modelAndView;
    }

    @GetMapping("create")
    public ModelAndView create(){
        ModelAndView modelAndView = new ModelAndView("/workspace/doctorAppointment/doctorAppointmentCreate.html");
        return modelAndView;
    }

    @GetMapping("myDoctorAppointment")
    public ModelAndView myDoctorAppointment(){
        ModelAndView modelAndView = new ModelAndView("/workspace/doctorAppointment/myDoctorAppointment.html");
        return modelAndView;
    }

    @GetMapping("selfDoctorAppointment")
    public ModelAndView selfDoctorAppointment(){
        ModelAndView modelAndView = new ModelAndView("/workspace/doctorAppointment/doctorAppointmentSelf.html");
        return modelAndView;
    }

    @RequestMapping("saveDoctorAppointment")
    public ResponseResult saveDoctorAppointment(DoctorAppointment doctorAppointment){
        return doctorAppointmentService.saveDoctorAppointment(doctorAppointment);
    }

    @RequestMapping("createDoctorAppointment")
    public ResponseResult createDoctorAppointment(DoctorAppointment doctorAppointment){
        return doctorAppointmentService.createDoctorAppointment(doctorAppointment);
    }

    @RequestMapping("deleteDoctorAppointment")
    public ResponseResult deleteDoctorAppointment(@RequestParam("id") Integer id){
        return doctorAppointmentService.deleteDoctorAppointment(id);
    }

    @RequestMapping("getDoctorAppointment")
    public ResponseResult getDoctorAppointment(@RequestParam("id") Integer id){
        return doctorAppointmentService.getDoctorAppointment(id);
    }

    @RequestMapping("queryDoctorAppointmentPage")
    public LayUiTableJson queryDoctorAppointment(String doctorCode, Integer patientId,String startTime, String endTime
            , @RequestParam(defaultValue = "1") int page
            , @RequestParam(defaultValue = "10") int limit){
        Page pageInfo = new Page();
        pageInfo.setCurrentPage(page);
        pageInfo.setSize(limit);
        ResponseResult ResponseResult = doctorAppointmentService.queryDoctorAppointmentPage(doctorCode,patientId,startTime,endTime,pageInfo);
        LayUiTableJson layUiTableJson = new LayUiTableJson(0,null,pageInfo.getAllRow(),(List)ResponseResult.getData());
        return layUiTableJson;
    }

    @RequestMapping("queryMyDoctorAppointmentPage")
    public LayUiTableJson queryMyDoctorAppointmentPage(String doctorCode,String startTime, String endTime
            , @RequestParam(defaultValue = "1") int page
            , @RequestParam(defaultValue = "10") int limit){
        Page pageInfo = new Page();
        pageInfo.setCurrentPage(page);
        pageInfo.setSize(limit);
        ResponseResult ResponseResult = doctorAppointmentService.queryMyDoctorAppointmentPage(doctorCode,startTime,endTime,pageInfo);
        LayUiTableJson layUiTableJson = new LayUiTableJson(0,null,pageInfo.getAllRow(),(List)ResponseResult.getData());
        return layUiTableJson;
    }

    @RequestMapping("querySelfDoctorAppointmentPage")
    public LayUiTableJson querySelfDoctorAppointmentPage(String appointmentTime, String appointmentDetailTime
            , @RequestParam(defaultValue = "1") int page
            , @RequestParam(defaultValue = "10") int limit){
        Page pageInfo = new Page();
        pageInfo.setCurrentPage(page);
        pageInfo.setSize(limit);
        ResponseResult ResponseResult = doctorAppointmentService.querySelfDoctorAppointmentPage(appointmentTime,appointmentDetailTime,pageInfo);
        LayUiTableJson layUiTableJson = new LayUiTableJson(0,null,pageInfo.getAllRow(),(List)ResponseResult.getData());
        return layUiTableJson;
    }

    @RequestMapping("queryLastAppointment")
    public ResponseResult queryLastAppointment(){
        return doctorAppointmentService.queryLastAppointment();
    }


}
